﻿using System;
using System.Net;
using System.Text;
using System.Threading;
using System.Collections.Generic;
using Demo_G.O.S.E.ServerEngine.Common;
using Demo_G.O.S.E.ServerEngine.Network;
using Demo_G.O.S.E.ServerEngine.Creature;
using Demo_G.O.S.E.ServerEngine.Network.DLL;
using System.Diagnostics;
using Demo_G.O.S.E.ServerEngine.Map;

namespace Demo_G.O.S.E.ServerEngine.Util
{
    //public delegate void CharacterCreatedEventHandler(CharacterCreatedEventArgs eventArgs);
    //public delegate void OpenDoorMacroEventHandler(OpenDoorMacroEventArgs eventArgs);
    //public delegate void SpeechEventHandler(SpeechEventArgs eventArgs);
    //public delegate void LoginEventHandler(LoginEventArgs eventArgs);
    public delegate void ServerListEventHandler( ServerListEventArgs eventArgs );
    //public delegate void HungerChangedEventHandler(HungerChangedEventArgs eventArgs);
    public delegate void CrashedEventHandler( CrashedEventArgs eventArgs );
    public delegate void ShutdownEventHandler( ShutdownEventArgs eventArgs );
    //public delegate void HelpRequestEventHandler(HelpRequestEventArgs eventArgs);
    //public delegate void DisarmRequestEventHandler(DisarmRequestEventArgs eventArgs);
    //public delegate void StunRequestEventHandler(StunRequestEventArgs eventArgs);
    //public delegate void OpenSpellbookRequestEventHandler(OpenSpellbookRequestEventArgs eventArgs);
    //public delegate void CastSpellRequestEventHandler(CastSpellRequestEventArgs eventArgs);
    //public delegate void AnimateRequestEventHandler(AnimateRequestEventArgs eventArgs);
    //public delegate void LogoutEventHandler(LogoutEventArgs eventArgs);
    public delegate void SocketConnectEventHandler(SocketConnectEventArgs eventArgs);
    //public delegate void ConnectedEventHandler(ConnectedEventArgs eventArgs);
    //public delegate void DisconnectedEventHandler(DisconnectedEventArgs eventArgs);
    //public delegate void RenameRequestEventHandler(RenameRequestEventArgs eventArgs);
    //public delegate void PlayerDeathEventHandler(PlayerDeathEventArgs eventArgs);
    //public delegate void VirtueGumpRequestEventHandler(VirtueGumpRequestEventArgs eventArgs);
    //public delegate void VirtueItemRequestEventHandler(VirtueItemRequestEventArgs eventArgs);
    //public delegate void VirtueMacroRequestEventHandler(VirtueMacroRequestEventArgs eventArgs);
    //public delegate void ChatRequestEventHandler(ChatRequestEventArgs eventArgs);
    public delegate void AccountLoginEventHandler( AccountLoginEventArgs eventArgs );
    //public delegate void PaperdollRequestEventHandler(PaperdollRequestEventArgs eventArgs);
    //public delegate void ProfileRequestEventHandler(ProfileRequestEventArgs eventArgs);
    //public delegate void ChangeProfileRequestEventHandler(ChangeProfileRequestEventArgs eventArgs);
    public delegate void AggressiveActionEventHandler( AggressiveActionEventArgs eventArgs );
    //public delegate void GameLoginEventHandler(GameLoginEventArgs eventArgs);
    //public delegate void DeleteRequestEventHandler(DeleteRequestEventArgs eventArgs);
    //public delegate void WorldLoadEventHandler();
    //public delegate void WorldSaveEventHandler(WorldSaveEventArgs eventArgs);
    //public delegate void SetAbilityEventHandler(SetAbilityEventArgs eventArgs);
    //public delegate void FastWalkEventHandler(FastWalkEventArgs eventArgs);
    //public delegate void ServerStartedEventHandler();
    //public delegate BaseGuild CreateGuildHandler(CreateGuildEventArgs eventArgs);
    //public delegate void GuildGumpRequestHandler(GuildGumpRequestArgs e);
    //public delegate void QuestGumpRequestHandler(QuestGumpRequestArgs e);

    //public class CreateGuildEventArgs : EventArgs
    //{
    //    private int m_Id;
    //    public int Id { get { return m_Id; } set { m_Id = value; } }

    //    public CreateGuildEventArgs(int id)
    //    {
    //        m_Id = id;
    //    }
    //}

    //public class GuildGumpRequestArgs : EventArgs
    //{
    //    private Mobile m_Mobile;

    //    public Mobile Mobile { get { return m_Mobile; } }

    //    public GuildGumpRequestArgs(Mobile mobile)
    //    {
    //        m_Mobile = mobile;
    //    }
    //}

    //public class QuestGumpRequestArgs : EventArgs
    //{
    //    private Mobile m_Mobile;

    //    public Mobile Mobile { get { return m_Mobile; } }

    //    public QuestGumpRequestArgs(Mobile mobile)
    //    {
    //        m_Mobile = mobile;
    //    }
    //}

    //public class SetAbilityEventArgs : EventArgs
    //{
    //    private Mobile m_Mobile;
    //    private int m_Index;

    //    public Mobile Mobile { get { return m_Mobile; } }
    //    public int Index { get { return m_Index; } }

    //    public SetAbilityEventArgs(Mobile mobile, int index)
    //    {
    //        m_Mobile = mobile;
    //        m_Index = index;
    //    }
    //}

    //public class DeleteRequestEventArgs : EventArgs
    //{
    //    private NetState m_State;
    //    private int m_Index;

    //    public NetState State { get { return m_State; } }
    //    public int Index { get { return m_Index; } }

    //    public DeleteRequestEventArgs(NetState state, int index)
    //    {
    //        m_State = state;
    //        m_Index = index;
    //    }
    //}

    //public class GameLoginEventArgs : EventArgs
    //{
    //    private NetState m_State;
    //    private string m_Username;
    //    private string m_Password;
    //    private bool m_Accepted;
    //    private CityInfo[] m_CityInfo;

    //    public NetState State { get { return m_State; } }
    //    public string Username { get { return m_Username; } }
    //    public string Password { get { return m_Password; } }
    //    public bool Accepted { get { return m_Accepted; } set { m_Accepted = value; } }
    //    public CityInfo[] CityInfo { get { return m_CityInfo; } set { m_CityInfo = value; } }

    //    public GameLoginEventArgs(NetState state, string un, string pw)
    //    {
    //        m_State = state;
    //        m_Username = un;
    //        m_Password = pw;
    //    }
    //}

    public class AggressiveActionEventArgs : EventArgs
    {
        private BaseCreature m_Aggressed;
        private BaseCreature m_Aggressor;
        private bool m_Criminal;

        public BaseCreature Aggressed { get { return m_Aggressed; } }
        public BaseCreature Aggressor { get { return m_Aggressor; } }
        public bool Criminal { get { return m_Criminal; } }

        private static Queue<AggressiveActionEventArgs> m_Pool = new Queue<AggressiveActionEventArgs>();

        public static AggressiveActionEventArgs Create( BaseCreature aggressed, BaseCreature aggressor, bool criminal )
        {
            AggressiveActionEventArgs args;

            if ( m_Pool.Count > 0 )
            {
                args = m_Pool.Dequeue();

                args.m_Aggressed = aggressed;
                args.m_Aggressor = aggressor;
                args.m_Criminal = criminal;
            }
            else
            {
                args = new AggressiveActionEventArgs( aggressed, aggressor, criminal );
            }

            return args;
        }

        private AggressiveActionEventArgs( BaseCreature aggressed, BaseCreature aggressor, bool criminal )
        {
            m_Aggressed = aggressed;
            m_Aggressor = aggressor;
            m_Criminal = criminal;
        }

        public void Release()
        {
            m_Pool.Enqueue( this );
        }
    }

    //public class ProfileRequestEventArgs : EventArgs
    //{
    //    private Mobile m_Beholder;
    //    private Mobile m_Beheld;

    //    public Mobile Beholder { get { return m_Beholder; } }
    //    public Mobile Beheld { get { return m_Beheld; } }

    //    public ProfileRequestEventArgs(Mobile beholder, Mobile beheld)
    //    {
    //        m_Beholder = beholder;
    //        m_Beheld = beheld;
    //    }
    //}

    //public class ChangeProfileRequestEventArgs : EventArgs
    //{
    //    private Mobile m_Beholder;
    //    private Mobile m_Beheld;
    //    private string m_Text;

    //    public Mobile Beholder { get { return m_Beholder; } }
    //    public Mobile Beheld { get { return m_Beheld; } }
    //    public string Text { get { return m_Text; } }

    //    public ChangeProfileRequestEventArgs(Mobile beholder, Mobile beheld, string text)
    //    {
    //        m_Beholder = beholder;
    //        m_Beheld = beheld;
    //        m_Text = text;
    //    }
    //}

    //public class PaperdollRequestEventArgs : EventArgs
    //{
    //    private Mobile m_Beholder;
    //    private Mobile m_Beheld;

    //    public Mobile Beholder { get { return m_Beholder; } }
    //    public Mobile Beheld { get { return m_Beheld; } }

    //    public PaperdollRequestEventArgs(Mobile beholder, Mobile beheld)
    //    {
    //        m_Beholder = beholder;
    //        m_Beheld = beheld;
    //    }
    //}

    /// <summary>
    /// 
    /// </summary>
    public class AccountLoginEventArgs : EventArgs
    {
        /// <summary>
        /// 
        /// </summary>
        private NetState m_State;
        /// <summary>
        /// 
        /// </summary>
        private string m_Username;
        /// <summary>
        /// 
        /// </summary>
        private string m_Password;
        /// <summary>
        /// 
        /// </summary>
        private bool m_Accepted = true;
        /// <summary>
        /// 
        /// </summary>
        private LoginReason m_RejectReason;

        /// <summary>
        /// 
        /// </summary>
        public NetState State
        {
            get { return m_State; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string Username
        {
            get { return m_Username; }
        }

        /// <summary>
        /// 
        /// </summary>
        public string Password
        {
            get { return m_Password; }
        }

        /// <summary>
        /// 
        /// </summary>
        public bool Accepted
        {
            get { return m_Accepted; }
            set { m_Accepted = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        public LoginReason RejectReason
        {
            get { return m_RejectReason; }
            set { m_RejectReason = value; }
        }

        public AccountLoginEventArgs( NetState netState, string strUsername, string strPassword )
        {
            m_State = netState;
            m_Username = strUsername;
            m_Password = strPassword;
        }
    }

    //public class VirtueItemRequestEventArgs : EventArgs
    //{
    //    private Mobile m_Beholder;
    //    private Mobile m_Beheld;
    //    private int m_GumpID;

    //    public Mobile Beholder { get { return m_Beholder; } }
    //    public Mobile Beheld { get { return m_Beheld; } }
    //    public int GumpID { get { return m_GumpID; } }

    //    public VirtueItemRequestEventArgs(Mobile beholder, Mobile beheld, int gumpID)
    //    {
    //        m_Beholder = beholder;
    //        m_Beheld = beheld;
    //        m_GumpID = gumpID;
    //    }
    //}

    //public class VirtueGumpRequestEventArgs : EventArgs
    //{
    //    private Mobile m_Beholder, m_Beheld;

    //    public Mobile Beholder { get { return m_Beholder; } }
    //    public Mobile Beheld { get { return m_Beheld; } }

    //    public VirtueGumpRequestEventArgs(Mobile beholder, Mobile beheld)
    //    {
    //        m_Beholder = beholder;
    //        m_Beheld = beheld;
    //    }
    //}

    //public class VirtueMacroRequestEventArgs : EventArgs
    //{
    //    private Mobile m_Mobile;
    //    private int m_VirtueID;

    //    public Mobile Mobile { get { return m_Mobile; } }
    //    public int VirtueID { get { return m_VirtueID; } }

    //    public VirtueMacroRequestEventArgs(Mobile mobile, int virtueID)
    //    {
    //        m_Mobile = mobile;
    //        m_VirtueID = virtueID;
    //    }
    //}

    //public class ChatRequestEventArgs : EventArgs
    //{
    //    private Mobile m_Mobile;

    //    public Mobile Mobile { get { return m_Mobile; } }

    //    public ChatRequestEventArgs(Mobile mobile)
    //    {
    //        m_Mobile = mobile;
    //    }
    //}

    //public class PlayerDeathEventArgs : EventArgs
    //{
    //    private Mobile m_Mobile;

    //    public Mobile Mobile { get { return m_Mobile; } }

    //    public PlayerDeathEventArgs(Mobile mobile)
    //    {
    //        m_Mobile = mobile;
    //    }
    //}

    //public class RenameRequestEventArgs : EventArgs
    //{
    //    private Mobile m_From, m_Target;
    //    private string m_Name;

    //    public Mobile From { get { return m_From; } }
    //    public Mobile Target { get { return m_Target; } }
    //    public string Name { get { return m_Name; } }

    //    public RenameRequestEventArgs(Mobile from, Mobile target, string name)
    //    {
    //        m_From = from;
    //        m_Target = target;
    //        m_Name = name;
    //    }
    //}

    //public class LogoutEventArgs : EventArgs
    //{
    //    private Mobile m_Mobile;

    //    public Mobile Mobile { get { return m_Mobile; } }

    //    public LogoutEventArgs(Mobile m)
    //    {
    //        m_Mobile = m;
    //    }
    //}

    /// <summary>
    /// 
    /// </summary>
    public class SocketConnectEventArgs : EventArgs
    {
        /// <summary>
        /// 
        /// </summary>
        private ServiceHandle m_ClientHandler    = null;
        /// <summary>
        /// 
        /// </summary>
        private bool m_AllowConnection                      = true;

        /// <summary>
        /// 
        /// </summary>
        public ServiceHandle Socket
        {
            get { return m_ClientHandler; }
        }

        /// <summary>
        /// 
        /// </summary>
        public bool AllowConnection
        {
            get { return m_AllowConnection; }
            set { m_AllowConnection = value; }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="clientHandler"></param>
        public SocketConnectEventArgs(ServiceHandle clientHandler)
        {
            m_ClientHandler     = clientHandler;
        }
    }

    //public class ConnectedEventArgs : EventArgs
    //{
    //    private Mobile m_Mobile;

    //    public Mobile Mobile { get { return m_Mobile; } }

    //    public ConnectedEventArgs(Mobile m)
    //    {
    //        m_Mobile = m;
    //    }
    //}

    //public class DisconnectedEventArgs : EventArgs
    //{
    //    private Mobile m_Mobile;

    //    public Mobile Mobile { get { return m_Mobile; } }

    //    public DisconnectedEventArgs(Mobile m)
    //    {
    //        m_Mobile = m;
    //    }
    //}

    //public class AnimateRequestEventArgs : EventArgs
    //{
    //    private Mobile m_Mobile;
    //    private string m_Action;

    //    public Mobile Mobile { get { return m_Mobile; } }
    //    public string Action { get { return m_Action; } }

    //    public AnimateRequestEventArgs(Mobile m, string action)
    //    {
    //        m_Mobile = m;
    //        m_Action = action;
    //    }
    //}

    //public class CastSpellRequestEventArgs : EventArgs
    //{
    //    private Mobile m_Mobile;
    //    private Item m_Spellbook;
    //    private int m_SpellID;

    //    public Mobile Mobile { get { return m_Mobile; } }
    //    public Item Spellbook { get { return m_Spellbook; } }
    //    public int SpellID { get { return m_SpellID; } }

    //    public CastSpellRequestEventArgs(Mobile m, int spellID, Item book)
    //    {
    //        m_Mobile = m;
    //        m_Spellbook = book;
    //        m_SpellID = spellID;
    //    }
    //}

    //public class OpenSpellbookRequestEventArgs : EventArgs
    //{
    //    private Mobile m_Mobile;
    //    private int m_Type;

    //    public Mobile Mobile { get { return m_Mobile; } }
    //    public int Type { get { return m_Type; } }

    //    public OpenSpellbookRequestEventArgs(Mobile m, int type)
    //    {
    //        m_Mobile = m;
    //        m_Type = type;
    //    }
    //}

    //public class StunRequestEventArgs : EventArgs
    //{
    //    private Mobile m_Mobile;

    //    public Mobile Mobile { get { return m_Mobile; } }

    //    public StunRequestEventArgs(Mobile m)
    //    {
    //        m_Mobile = m;
    //    }
    //}

    //public class DisarmRequestEventArgs : EventArgs
    //{
    //    private Mobile m_Mobile;

    //    public Mobile Mobile { get { return m_Mobile; } }

    //    public DisarmRequestEventArgs(Mobile m)
    //    {
    //        m_Mobile = m;
    //    }
    //}

    //public class HelpRequestEventArgs : EventArgs
    //{
    //    private Mobile m_Mobile;

    //    public Mobile Mobile { get { return m_Mobile; } }

    //    public HelpRequestEventArgs(Mobile m)
    //    {
    //        m_Mobile = m;
    //    }
    //}

    public class ShutdownEventArgs : EventArgs
    {
        public ShutdownEventArgs()
        {
        }
    }

    public class CrashedEventArgs : EventArgs
    {

        private Exception m_Exception = null;
        public Exception Exception
        {
            get { return m_Exception; }
        }

        private bool m_Close = false;
        public bool Close
        { 
            get { return m_Close; }
            set { m_Close = value; }
        }

        public CrashedEventArgs( Exception exception )
        {
            m_Exception = exception;
        }
    }

    //public class HungerChangedEventArgs : EventArgs
    //{
    //    private Mobile m_Mobile;
    //    private int m_OldValue;

    //    public Mobile Mobile { get { return m_Mobile; } }
    //    public int OldValue { get { return m_OldValue; } }

    //    public HungerChangedEventArgs(Mobile mobile, int oldValue)
    //    {
    //        m_Mobile = mobile;
    //        m_OldValue = oldValue;
    //    }
    //}


    public class ServerListEventArgs : EventArgs
    {
        //private NetState m_State;
        //private IAccount m_Account;
        private bool m_Rejected;
        private List<ServerInfo> m_Servers = new List<ServerInfo>();

        //public NetState State
        //{
        //    get { return m_State; }
        //}

        //public IAccount Account { get { return m_Account; } }

        public bool Rejected
        {
            get { return m_Rejected; }
            set { m_Rejected = value; }
        }

        public List<ServerInfo> Servers
        {
            get { return m_Servers; }
        }

        public void AddServer( string name, IPEndPoint address )
        {
            AddServer( name, 0, 0, TimeZone.CurrentTimeZone, address );
        }

        public void AddServer( string name, long iGuid, int fullPercent, TimeZone tz, IPEndPoint address )
        {
            m_Servers.Add( new ServerInfo( name, iGuid, fullPercent, tz, address ) );
        }

        //public ServerListEventArgs( NetState state, IAccount account )
        //{
        //    m_State = state;
        //    m_Account = account;
        //    m_Servers = new List<ServerInfo>();
        //}
    }

    //public struct SkillNameValue
    //{
    //    private SkillName m_Name;
    //    private int m_Value;

    //    public SkillName Name { get { return m_Name; } }
    //    public int Value { get { return m_Value; } }

    //    public SkillNameValue(SkillName name, int value)
    //    {
    //        m_Name = name;
    //        m_Value = value;
    //    }
    //}

    //public class CharacterCreatedEventArgs : EventArgs
    //{
    //    private NetState m_State;
    //    private IAccount m_Account;
    //    private CityInfo m_City;
    //    private SkillNameValue[] m_Skills;
    //    private int m_ShirtHue, m_PantsHue;
    //    private int m_HairID, m_HairHue;
    //    private int m_BeardID, m_BeardHue;
    //    private string m_Name;
    //    private bool m_Female;
    //    private int m_Hue;
    //    private int m_Str, m_Dex, m_Int;
    //    private int m_Profession;
    //    private Mobile m_Mobile;

    //    private Race m_Race;

    //    public NetState State { get { return m_State; } }
    //    public IAccount Account { get { return m_Account; } }
    //    public Mobile Mobile { get { return m_Mobile; } set { m_Mobile = value; } }
    //    public string Name { get { return m_Name; } }
    //    public bool Female { get { return m_Female; } }
    //    public int Hue { get { return m_Hue; } }
    //    public int Str { get { return m_Str; } }
    //    public int Dex { get { return m_Dex; } }
    //    public int Int { get { return m_Int; } }
    //    public CityInfo City { get { return m_City; } }
    //    public SkillNameValue[] Skills { get { return m_Skills; } }
    //    public int ShirtHue { get { return m_ShirtHue; } }
    //    public int PantsHue { get { return m_PantsHue; } }
    //    public int HairID { get { return m_HairID; } }
    //    public int HairHue { get { return m_HairHue; } }
    //    public int BeardID { get { return m_BeardID; } }
    //    public int BeardHue { get { return m_BeardHue; } }
    //    public int Profession { get { return m_Profession; } set { m_Profession = value; } }
    //    public Race Race { get { return m_Race; } }

    //    public CharacterCreatedEventArgs(NetState state, IAccount a, string name, bool female, int hue, int str, int dex, int intel, CityInfo city, SkillNameValue[] skills, int shirtHue, int pantsHue, int hairID, int hairHue, int beardID, int beardHue, int profession, Race race)
    //    {
    //        m_State = state;
    //        m_Account = a;
    //        m_Name = name;
    //        m_Female = female;
    //        m_Hue = hue;
    //        m_Str = str;
    //        m_Dex = dex;
    //        m_Int = intel;
    //        m_City = city;
    //        m_Skills = skills;
    //        m_ShirtHue = shirtHue;
    //        m_PantsHue = pantsHue;
    //        m_HairID = hairID;
    //        m_HairHue = hairHue;
    //        m_BeardID = beardID;
    //        m_BeardHue = beardHue;
    //        m_Profession = profession;
    //        m_Race = race;
    //    }
    //}

    //public class OpenDoorMacroEventArgs : EventArgs
    //{
    //    private Mobile m_Mobile;

    //    public Mobile Mobile { get { return m_Mobile; } }

    //    public OpenDoorMacroEventArgs(Mobile mobile)
    //    {
    //        m_Mobile = mobile;
    //    }
    //}

    //public class SpeechEventArgs : EventArgs
    //{
    //    private Mobile m_Mobile;
    //    private string m_Speech;
    //    private MessageType m_Type;
    //    private int m_Hue;
    //    private int[] m_Keywords;
    //    private bool m_Handled;
    //    private bool m_Blocked;

    //    public Mobile Mobile { get { return m_Mobile; } }
    //    public string Speech { get { return m_Speech; } set { m_Speech = value; } }
    //    public MessageType Type { get { return m_Type; } }
    //    public int Hue { get { return m_Hue; } }
    //    public int[] Keywords { get { return m_Keywords; } }
    //    public bool Handled { get { return m_Handled; } set { m_Handled = value; } }
    //    public bool Blocked { get { return m_Blocked; } set { m_Blocked = value; } }

    //    public bool HasKeyword(int keyword)
    //    {
    //        for (int i = 0; i < m_Keywords.Length; ++i)
    //            if (m_Keywords[i] == keyword)
    //                return true;

    //        return false;
    //    }

    //    public SpeechEventArgs(Mobile mobile, string speech, MessageType type, int hue, int[] keywords)
    //    {
    //        m_Mobile = mobile;
    //        m_Speech = speech;
    //        m_Type = type;
    //        m_Hue = hue;
    //        m_Keywords = keywords;
    //    }
    //}

    //public class LoginEventArgs : EventArgs
    //{
    //    private Mobile m_Mobile;

    //    public Mobile Mobile { get { return m_Mobile; } }

    //    public LoginEventArgs(Mobile mobile)
    //    {
    //        m_Mobile = mobile;
    //    }
    //}

    //public class WorldSaveEventArgs : EventArgs
    //{
    //    private bool m_Msg;

    //    public bool Message { get { return m_Msg; } }

    //    public WorldSaveEventArgs(bool msg)
    //    {
    //        m_Msg = msg;
    //    }
    //}

    //public class FastWalkEventArgs
    //{
    //    private NetState m_State;
    //    private bool m_Blocked;

    //    public FastWalkEventArgs(NetState state)
    //    {
    //        m_State = state;
    //        m_Blocked = false;
    //    }

    //    public NetState NetState { get { return m_State; } }
    //    public bool Blocked { get { return m_Blocked; } set { m_Blocked = value; } }
    //}

    /// <summary>
    /// 
    /// </summary>
    public static class EventSink
    {
        /// <summary>
        /// 
        /// </summary>
        public static class BaseCharacter
        {
            #region zh-CHS MoveTo 共有静态事件 | en Public Static Event

            #region zh-CHS 私有成员变量 | en Private Member Variables
            /// <summary>
            /// 
            /// </summary>
            private static EventHandler<MoveToEventArgs> m_ThreadMoveTo;
            /// <summary>
            /// 
            /// </summary>
            private static ReaderWriterLockSlim m_LockThreadMoveTo = new ReaderWriterLockSlim();
            #endregion
            /// <summary>
            /// World可处理的时间片
            /// </summary>
            public static event EventHandler<MoveToEventArgs> MoveTo
            {
                add
                {
                    ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadMoveTo );
                    {
                        m_ThreadMoveTo += value;
                    }
                    ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadMoveTo );
                }
                remove
                {
                    ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadMoveTo );
                    {
                        m_ThreadMoveTo -= value;
                    }
                    ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadMoveTo );
                }
            }

            /// <summary>
            /// 
            /// </summary>
            /// <param name="eventArgs"></param>
            internal static MoveToEventArgs InvokeMoveTo( BaseCreature baseCreature, Point3D newLocation )
            {
                EventHandler<MoveToEventArgs> tempMoveTo = m_ThreadMoveTo;
                if ( tempMoveTo != null )
                {
                    MoveToEventArgs moveToEventArgs = new MoveToEventArgs( baseCreature, newLocation );
                    Debug.Assert( moveToEventArgs == null );

                    tempMoveTo( baseCreature, moveToEventArgs );

                    return moveToEventArgs;
                }

                return null;
            }

            #endregion

            #region zh-CHS MoveToWorld 共有静态事件 | en Public Static Event

            #region zh-CHS 私有成员变量 | en Private Member Variables
            /// <summary>
            /// 
            /// </summary>
            private static EventHandler<MoveToWorldEventArgs> m_ThreadMoveToWorld;
            /// <summary>
            /// 
            /// </summary>
            private static ReaderWriterLockSlim m_LockThreadMoveToWorld = new ReaderWriterLockSlim();
            #endregion
            /// <summary>
            /// World可处理的时间片
            /// </summary>
            public static event EventHandler<MoveToWorldEventArgs> MoveToWorld
            {
                add
                {
                    ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadMoveToWorld );
                    {
                        m_ThreadMoveToWorld += value;
                    }
                    ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadMoveToWorld );
                }
                remove
                {
                    ReaderWriterLockSlimEx.EnterWriteLock( m_LockThreadMoveToWorld );
                    {
                        m_ThreadMoveToWorld -= value;
                    }
                    ReaderWriterLockSlimEx.ExitWriteLock( m_LockThreadMoveToWorld );
                }
            }

            /// <summary>
            /// 
            /// </summary>
            /// <param name="eventArgs"></param>
            internal static MoveToWorldEventArgs InvokeMoveToWorld( BaseCreature baseCreature, Point3D newLocation, BaseMap newBaseMap )
            {
                EventHandler<MoveToWorldEventArgs> tempMoveToWorld = m_ThreadMoveToWorld;
                if ( tempMoveToWorld != null )
                {
                    MoveToWorldEventArgs moveToWorldEventArgs = new MoveToWorldEventArgs( baseCreature, newLocation, newBaseMap );
                    Debug.Assert( moveToWorldEventArgs == null );

                    tempMoveToWorld( baseCreature, moveToWorldEventArgs );

                    return moveToWorldEventArgs;
                }

                return null;
            }

            #endregion
        }

    //    public static event CharacterCreatedEventHandler CharacterCreated;
    //    public static event OpenDoorMacroEventHandler OpenDoorMacroUsed;
    //    public static event SpeechEventHandler Speech;
    //    public static event LoginEventHandler Login;
        public static event ServerListEventHandler ServerList;
    //    public static event HungerChangedEventHandler HungerChanged;
        public static event CrashedEventHandler Crashed;
        public static event ShutdownEventHandler Shutdown;
    //    public static event HelpRequestEventHandler HelpRequest;
    //    public static event DisarmRequestEventHandler DisarmRequest;
    //    public static event StunRequestEventHandler StunRequest;
    //    public static event OpenSpellbookRequestEventHandler OpenSpellbookRequest;
    //    public static event CastSpellRequestEventHandler CastSpellRequest;
    //    public static event AnimateRequestEventHandler AnimateRequest;
    //    public static event LogoutEventHandler Logout;
        public static event SocketConnectEventHandler SocketConnect = null;
    //    public static event ConnectedEventHandler Connected;
    //    public static event DisconnectedEventHandler Disconnected;
    //    public static event RenameRequestEventHandler RenameRequest;
    //    public static event PlayerDeathEventHandler PlayerDeath;
    //    public static event VirtueGumpRequestEventHandler VirtueGumpRequest;
    //    public static event VirtueItemRequestEventHandler VirtueItemRequest;
    //    public static event VirtueMacroRequestEventHandler VirtueMacroRequest;
    //    public static event ChatRequestEventHandler ChatRequest;
        public static event AccountLoginEventHandler AccountLogin;
    //    public static event PaperdollRequestEventHandler PaperdollRequest;
    //    public static event ProfileRequestEventHandler ProfileRequest;
    //    public static event ChangeProfileRequestEventHandler ChangeProfileRequest;
        public static event AggressiveActionEventHandler AggressiveAction;
    //    public static event CommandEventHandler Command;
    //    public static event GameLoginEventHandler GameLogin;
    //    public static event DeleteRequestEventHandler DeleteRequest;
    //    public static event WorldLoadEventHandler WorldLoad;
    //    public static event WorldSaveEventHandler WorldSave;
    //    public static event SetAbilityEventHandler SetAbility;
    //    public static event FastWalkEventHandler FastWalk;
    //    public static event CreateGuildHandler CreateGuild;
    //    public static event ServerStartedEventHandler ServerStarted;
    //    public static event GuildGumpRequestHandler GuildGumpRequest;
    //    public static event QuestGumpRequestHandler QuestGumpRequest;

    //    public static void InvokeServerStarted()
    //    {
    //        if (ServerStarted != null)
    //            ServerStarted();
    //    }

    //    public static BaseGuild InvokeCreateGuild(CreateGuildEventArgs eventArgs)
    //    {
    //        if (CreateGuild != null)
    //            return CreateGuild(eventArgs);
    //        else
    //            return null;
    //    }

    //    public static void InvokeSetAbility(SetAbilityEventArgs eventArgs)
    //    {
    //        if (SetAbility != null)
    //            SetAbility(eventArgs);
    //    }

    //    public static void InvokeGuildGumpRequest(GuildGumpRequestArgs e)
    //    {
    //        if (GuildGumpRequest != null)
    //            GuildGumpRequest(eventArgs);
    //    }

    //    public static void InvokeQuestGumpRequest(QuestGumpRequestArgs e)
    //    {
    //        if (QuestGumpRequest != null)
    //            QuestGumpRequest(eventArgs);
    //    }

    //    public static void InvokeFastWalk(FastWalkEventArgs eventArgs)
    //    {
    //        if (FastWalk != null)
    //            FastWalk(eventArgs);
    //    }

    //    public static void InvokeDeleteRequest(DeleteRequestEventArgs eventArgs)
    //    {
    //        if (DeleteRequest != null)
    //            DeleteRequest(eventArgs);
    //    }

    //    public static void InvokeGameLogin(GameLoginEventArgs eventArgs)
    //    {
    //        if (GameLogin != null)
    //            GameLogin(eventArgs);
    //    }

    //    public static void InvokeCommand(CommandEventArgs eventArgs)
    //    {
    //        if (Command != null)
    //            Command(eventArgs);
    //    }

        public static void InvokeAggressiveAction( AggressiveActionEventArgs eventArgs )
        {
            if ( AggressiveAction != null )
                AggressiveAction( eventArgs );
        }

    //    public static void InvokeProfileRequest(ProfileRequestEventArgs eventArgs)
    //    {
    //        if (ProfileRequest != null)
    //            ProfileRequest(eventArgs);
    //    }

    //    public static void InvokeChangeProfileRequest(ChangeProfileRequestEventArgs eventArgs)
    //    {
    //        if (ChangeProfileRequest != null)
    //            ChangeProfileRequest(eventArgs);
    //    }

    //    public static void InvokePaperdollRequest(PaperdollRequestEventArgs eventArgs)
    //    {
    //        if (PaperdollRequest != null)
    //            PaperdollRequest(eventArgs);
    //    }

        public static void InvokeAccountLogin( AccountLoginEventArgs eventArgs )
        {
            if ( AccountLogin != null )
                AccountLogin( eventArgs );
        }

    //    public static void InvokeChatRequest(ChatRequestEventArgs eventArgs)
    //    {
    //        if (ChatRequest != null)
    //            ChatRequest(eventArgs);
    //    }

    //    public static void InvokeVirtueItemRequest(VirtueItemRequestEventArgs eventArgs)
    //    {
    //        if (VirtueItemRequest != null)
    //            VirtueItemRequest(eventArgs);
    //    }

    //    public static void InvokeVirtueGumpRequest(VirtueGumpRequestEventArgs eventArgs)
    //    {
    //        if (VirtueGumpRequest != null)
    //            VirtueGumpRequest(eventArgs);
    //    }

    //    public static void InvokeVirtueMacroRequest(VirtueMacroRequestEventArgs eventArgs)
    //    {
    //        if (VirtueMacroRequest != null)
    //            VirtueMacroRequest(eventArgs);
    //    }

    //    public static void InvokePlayerDeath(PlayerDeathEventArgs eventArgs)
    //    {
    //        if (PlayerDeath != null)
    //            PlayerDeath(eventArgs);
    //    }

    //    public static void InvokeRenameRequest(RenameRequestEventArgs eventArgs)
    //    {
    //        if (RenameRequest != null)
    //            RenameRequest(eventArgs);
    //    }

    //    public static void InvokeLogout(LogoutEventArgs eventArgs)
    //    {
    //        if (Logout != null)
    //            Logout(eventArgs);
    //    }

        /// <summary>
        /// 新的客户连接上来时回调
        /// </summary>
        /// <param name="eventArgs"></param>
        public static void InvokeSocketConnect(SocketConnectEventArgs eventArgs)
        {
            if (SocketConnect != null)
                SocketConnect(eventArgs);
        }

    //    public static void InvokeConnected(ConnectedEventArgs eventArgs)
    //    {
    //        if (Connected != null)
    //            Connected(eventArgs);
    //    }

    //    public static void InvokeDisconnected(DisconnectedEventArgs eventArgs)
    //    {
    //        if (Disconnected != null)
    //            Disconnected(eventArgs);
    //    }

    //    public static void InvokeAnimateRequest(AnimateRequestEventArgs eventArgs)
    //    {
    //        if (AnimateRequest != null)
    //            AnimateRequest(eventArgs);
    //    }

    //    public static void InvokeCastSpellRequest(CastSpellRequestEventArgs eventArgs)
    //    {
    //        if (CastSpellRequest != null)
    //            CastSpellRequest(eventArgs);
    //    }

    //    public static void InvokeOpenSpellbookRequest(OpenSpellbookRequestEventArgs eventArgs)
    //    {
    //        if (OpenSpellbookRequest != null)
    //            OpenSpellbookRequest(eventArgs);
    //    }

    //    public static void InvokeDisarmRequest(DisarmRequestEventArgs eventArgs)
    //    {
    //        if (DisarmRequest != null)
    //            DisarmRequest(eventArgs);
    //    }

    //    public static void InvokeStunRequest(StunRequestEventArgs eventArgs)
    //    {
    //        if (StunRequest != null)
    //            StunRequest(eventArgs);
    //    }

    //    public static void InvokeHelpRequest(HelpRequestEventArgs eventArgs)
    //    {
    //        if (HelpRequest != null)
    //            HelpRequest(eventArgs);
    //    }

        public static void InvokeShutdown( ShutdownEventArgs eventArgs )
        {
            if ( Shutdown != null )
                Shutdown( eventArgs );
        }

        public static void InvokeCrashed( CrashedEventArgs eventArgs )
        {
            if ( Crashed != null )
                Crashed( eventArgs );
        }

    //    public static void InvokeHungerChanged(HungerChangedEventArgs eventArgs)
    //    {
    //        if (HungerChanged != null)
    //            HungerChanged(eventArgs);
    //    }



        public static void InvokeServerList( ServerListEventArgs eventArgs )
        {
            if ( ServerList != null )
                ServerList( eventArgs );
        }

    //    public static void InvokeLogin(LoginEventArgs eventArgs)
    //    {
    //        if (Login != null)
    //            Login(eventArgs);
    //    }

    //    public static void InvokeSpeech(SpeechEventArgs eventArgs)
    //    {
    //        if (Speech != null)
    //            Speech(eventArgs);
    //    }

    //    public static void InvokeCharacterCreated(CharacterCreatedEventArgs eventArgs)
    //    {
    //        if (CharacterCreated != null)
    //            CharacterCreated(eventArgs);
    //    }

    //    public static void InvokeOpenDoorMacroUsed(OpenDoorMacroEventArgs eventArgs)
    //    {
    //        if (OpenDoorMacroUsed != null)
    //            OpenDoorMacroUsed(eventArgs);
    //    }

    //    public static void InvokeWorldLoad()
    //    {
    //        if (WorldLoad != null)
    //            WorldLoad();
    //    }

    //    public static void InvokeWorldSave(WorldSaveEventArgs eventArgs)
    //    {
    //        if (WorldSave != null)
    //            WorldSave(eventArgs);
    //    }
    }
}

